package com.heu.blood.bloodtest.controller;

import com.heu.blood.bloodtest.entity.BloodSampleEntity;
import com.heu.blood.bloodtest.service.BloodSampleService;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 血液样本表（血库）
 *
 * @author lrz
 * @email lrz@heu.com
 * @date 2023-08-28 17:09:07
 */
@RestController
@RequestMapping("bloodtest/bloodsample")
public class BloodSampleController {
    @Autowired
    private BloodSampleService bloodSampleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodSampleService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据样本单号查询样本信息
     * @param bloodSampleId
     * @return
     */
    @GetMapping("/getBySampleId")
    public R getBySampleId(String bloodSampleId){
        BloodSampleEntity bloodSampleEntity = bloodSampleService.getBySampleId(bloodSampleId);
        return R.ok().put("data", bloodSampleEntity);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		BloodSampleEntity bloodSample = bloodSampleService.getById(id);

        return R.ok().put("bloodSample", bloodSample);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BloodSampleEntity bloodSample){
		bloodSampleService.save(bloodSample);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BloodSampleEntity bloodSample){
		bloodSampleService.updateById(bloodSample);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		bloodSampleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
